package com.huawei.appgallery.appcomment.ui;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import com.huawei.appgallery.appcomment.api.AppCommentFragmentProtocol;
import com.huawei.appgallery.appcomment.api.AppCommentFragmentProtocol.Request;
import com.huawei.appgallery.appcomment.impl.bean.AppInfoBean;
import com.huawei.appgallery.appcomment.impl.bean.GetCommentResBean;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSSelector;
import com.huawei.appgallery.foundation.ui.css.CSSStyleSheet;
import com.huawei.appgallery.foundation.ui.css.CSSView;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b;
import com.huawei.appgallery.foundation.ui.framework.widget.PullUpListView.a;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.hmf.annotation.FragmentDefine;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import com.huawei.secure.android.common.intent.SafeIntent;
import java.util.ArrayList;
import java.util.List;
import o.bcb;
import o.bcg;
import o.bcg.d;
import o.bdi;
import o.bdm;
import o.bdm.e;
import o.bds;
import o.bdy;
import o.bdy.c;
import o.cdh;
import o.cgs;
import o.cip;
import o.ciy;
import o.ciz;
import o.cvt;
import o.ll;

@FragmentDefine(alias = "AppComment", protocol = AppCommentFragmentProtocol.class)
public class AppCommentFragment extends TaskFragment<AppCommentFragmentProtocol> implements a, c, ciz, ciy {
    private String ʹ;
    private int ʼ;
    private BroadcastReceiver ʼˊ = new SafeBroadcastReceiver(this) {
        final /* synthetic */ AppCommentFragment ˋ;

        {
            this.ˋ = r1;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            SafeIntent safeIntent = new SafeIntent(intent);
            String stringExtra;
            if ("com.huawei.appmarket.service.broadcast.CommentAdded".equals(safeIntent.getAction())) {
                stringExtra = safeIntent.getStringExtra("ACTION_PARAM_COMMENT_ADDED_TYPE_APPID");
                if (this.ˋ.ˋ != null && this.ˋ.ˋ.ˎ() != null && this.ˋ.ˋ.ˎ().equals(stringExtra) && this.ˋ.ˏ != null && !this.ˋ.ॱॱ) {
                    this.ˋ.ˏ.ᐝ();
                    this.ˋ.ʽᐝ();
                }
            } else if ("com.huawei.appmarket.service.broadcast.Approved".equals(safeIntent.getAction())) {
                this.ˋ.ˏ.ˋ((e) safeIntent.getSerializableExtra("ACTION_PARAM_COMMENT_APPROVED"));
            } else if ("com.huawei.appmarket.service.broadcast.CommentCollect".equals(safeIntent.getAction())) {
                this.ˋ.ˏ.ˏ((e) safeIntent.getSerializableExtra("ACTION_PARAM_COMMENT_CANCEL_COLLECT_TYPE_COMMENTID"));
            } else if ("com.huawei.appmarket.service.broadcast.Dissed".equals(safeIntent.getAction())) {
                this.ˋ.ˏ.ˋ((e) safeIntent.getSerializableExtra("ACTION_PARAM_COMMENT_DISSED"));
            } else if ("com.huawei.appmarket.service.broadcast.CommentDeleted".equals(safeIntent.getAction())) {
                stringExtra = safeIntent.getStringExtra("ACTION_PARAM_COMMENT_DEL_TYPE_COMMENTID");
                bcb.ˋ.ˎ("AppCommentFragment", "delete Comment: commentId=" + stringExtra);
                this.ˋ.ˏ.ˊ(stringExtra);
            }
        }
    };
    private int ʽ = 1;
    private bdy ˊ = null;
    private AppInfoBean ˋ;
    private cip ˎ;
    private bdm ˏ = null;
    private ViewGroup ॱ;
    private boolean ॱॱ = false;
    private String ᐝ;
    private int ﹳ;
    private String ﾞ;
    private int ﾟ;

    public void ˏ(Bundle bundle) {
        this.ˋ = new AppInfoBean();
        AppCommentFragmentProtocol appCommentFragmentProtocol = (AppCommentFragmentProtocol) ˆ();
        if (!(appCommentFragmentProtocol == null || appCommentFragmentProtocol.ˋ() == null)) {
            Request ˋ = appCommentFragmentProtocol.ˋ();
            String ॱ = ˋ.ॱ();
            String ˊ = ˋ.ˊ();
            this.ˋ.ˎ(ॱ);
            this.ˋ.ˊ(ˊ);
            this.ﾞ = ˋ.ˋ();
            this.ʹ = ˋ.ˏ();
            this.ﾟ = ˋ.ˎ();
        }
        ॱˋ(true);
        super.ˏ(bundle);
    }

    public void ˋ(TaskFragment taskFragment, List<cvt> list) {
        cvt ॱ = ॱ(this.ᐝ, this.ʽ, this.ʼ);
        ॱ.setServiceType_(cdh.ˎ(ॱˋ()));
        list.add(ॱ);
        this.ˏ.ॱ((bdi) ॱ);
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.ॱ = (ViewGroup) layoutInflater.inflate(d.ˋ, viewGroup, false);
        IntentFilter intentFilter = new IntentFilter("com.huawei.appmarket.service.broadcast.CommentAdded");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.Approved");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentCollect");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.Dissed");
        intentFilter.addAction("com.huawei.appmarket.service.broadcast.CommentDeleted");
        ll.ˏ(ॱˋ()).ˏ(this.ʼˊ, intentFilter);
        this.ˊ = new bdy();
        this.ˊ.ˏ((c) this);
        this.ˊ.ˏ((TaskFragment) this);
        if (this.ˏ == null) {
            this.ˏ = new bdm();
        }
        if (!TextUtils.isEmpty(this.ﾞ)) {
            this.ˏ.ˎ(CSSStyleSheet.parse(this.ﾞ));
            this.ˏ.ˎ(this.ʹ);
        }
        View ˏ = this.ˊ.ˏ(layoutInflater, viewGroup, bundle);
        ˉॱ();
        ((FrameLayout) this.ॱ.findViewById(bcg.e.ʾॱ)).addView(ˏ, new LayoutParams(-1, -1));
        if (this.ˏ.ˊ() == null) {
            ˊʽ();
            ˋʽ();
            ॱˋ(false);
            ʿˊ();
        } else {
            if (this.ˎ != null) {
                this.ˎ.ˎ(this.ॱ.findViewById(bcg.e.ߵ));
                if (this.ﹳ == ResponseBean.SERVER_DELAY_RETRY) {
                    this.ˎ.ˋ();
                }
                this.ॱ.findViewById(bcg.e.ˈᐝ).setBackgroundColor(ᐝॱ().getColor(bcg.a.ॱ));
                this.ˎ.ॱ(0);
            }
            ˋʽ();
        }
        return this.ॱ;
    }

    private bdi ॱ(String str, int i, int i2) {
        bdi o_bdi = new bdi();
        o_bdi.ˋ(this.ˋ.ˎ());
        o_bdi.ˏ(12);
        o_bdi.ॱ(this.ˏ.ˋॱ());
        o_bdi.setServiceType_(cdh.ˎ(ॱˋ()));
        o_bdi.ˏ(str);
        o_bdi.ˋ(i);
        o_bdi.ˊ(i2);
        return o_bdi;
    }

    public boolean ˊ(TaskFragment taskFragment, b bVar) {
        if (bVar.ˋ.getResponseCode() != 0) {
            if (this.ˊ != null) {
                this.ˊ.ˊ(false, bVar.ˊ, bVar.ˋ);
            }
            this.ﹳ = bVar.ˋ.getResponseCode();
            if (this.ˎ != null) {
                this.ˎ.ˏ(bVar.ˋ.getResponseCode(), true);
            }
        } else if (bVar.ˋ.getRtnCode_() != 0) {
            if (this.ˊ != null) {
                this.ˊ.ˊ(false, bVar.ˊ, bVar.ˋ);
            }
            if (this.ˎ != null) {
                this.ˎ.ˏ(1, true);
            }
        } else {
            if (this.ˏ.ˋॱ() == 1) {
                this.ˏ.ᐝ();
            }
            ˋʼ();
            bdi o_bdi = (bdi) bVar.ˊ;
            GetCommentResBean getCommentResBean = (GetCommentResBean) bVar.ˋ;
            if (!ˊ(getCommentResBean)) {
                this.ˏ.ˎ(o_bdi, getCommentResBean);
                ॱˋ(true);
            }
            int ˋॱ = this.ˏ.ˋॱ() + 1;
            this.ˏ.ˋ(ˋॱ);
            if (ˋॱ > getCommentResBean.ˊ()) {
                this.ˏ.ˋ(false);
            } else {
                this.ˏ.ˋ(true);
            }
            if (this.ˊ != null) {
                this.ˊ.ˊ(true, o_bdi, getCommentResBean);
            }
            this.ᶥॱ = null;
        }
        return false;
    }

    private boolean ˊ(GetCommentResBean getCommentResBean) {
        if (cgs.ˋ(getCommentResBean.ˋ()) && cgs.ˋ(getCommentResBean.ʼ()) && cgs.ˋ(getCommentResBean.ᐝ())) {
            return true;
        }
        return false;
    }

    private void ˉॱ() {
        List arrayList = new ArrayList();
        arrayList.add(this.ˋ);
        this.ˊ.ˋ(arrayList);
    }

    public void ʽᐝ() {
        if (this.ˊ != null) {
            this.ˊ.ˊ();
        }
        ʿˊ();
    }

    public void ʼᐝ() {
        if (this.ˊ != null) {
            this.ˊ.ˏ();
        }
        ʿˊ();
    }

    public boolean ˊ(String str, int i, int i2) {
        if (this.ॱॱ) {
            return false;
        }
        this.ᐝ = str;
        this.ʽ = i;
        this.ʼ = i2;
        this.ˏ.ˋ(1);
        ʽᐝ();
        return true;
    }

    private void ˋʽ() {
        if (this.ˎ != null && this.ﾟ == 1 && this.ﾞ != null && this.ʹ != null && this.ˎ.ॱ() != null) {
            CSSSelector cSSSelector = new CSSSelector(this.ʹ);
            CSSStyleSheet parse = CSSStyleSheet.parse(this.ﾞ);
            if (parse != null) {
                CSSRule rule = cSSSelector.getRule(parse.getRootRule());
                if (rule != null) {
                    CSSView.wrap(this.ˎ.ॱ(), rule).render();
                }
            }
        }
    }

    public bds ˊʻ() {
        return this.ˏ;
    }

    public void ᐝ() {
        try {
            ll.ˏ(ॱˋ()).ˋ(this.ʼˊ);
        } catch (Exception e) {
            bcb.ˋ.ˏ("AppCommentFragment", "onDestroyView error:" + e.toString());
        }
        if (this.ˊ != null) {
            try {
                this.ˊ.ˋ();
            } catch (Exception e2) {
                bcb.ˋ.ˏ("AppCommentFragment", "onDestroyView error:" + e2.toString());
            }
        }
        ˋʻ();
        super.ᐝ();
    }

    private void ˋʻ() {
        this.ˊ = null;
        this.ॱ = null;
    }

    public void ˈॱ() {
    }

    public void ˊʼ() {
    }

    public void ʿॱ() {
    }

    public boolean ad_() {
        if (this.ˊ != null) {
            return this.ˊ.ˎ();
        }
        return false;
    }

    public void ˋ(int i) {
    }

    public void ʽˊ() {
    }

    public void ʾॱ() {
        if (this.ˊ != null) {
            this.ˊ.ॱ();
        }
    }

    private void ˊʽ() {
        if (this.ˎ == null) {
            this.ˎ = new cip();
            this.ˎ.ˎ(this.ॱ.findViewById(bcg.e.ߵ));
            this.ॱ.findViewById(bcg.e.ˈᐝ).setBackgroundColor(ᐝॱ().getColor(bcg.a.ॱ));
            this.ˎ.ˋ(new OnClickListener(this) {
                final /* synthetic */ AppCommentFragment ˎ;

                {
                    this.ˎ = r1;
                }

                public void onClick(View view) {
                    this.ˎ.ʿˊ();
                }
            });
        }
        ˋʽ();
        this.ˎ.ॱ(0);
        this.ॱॱ = true;
    }

    private void ˋʼ() {
        this.ॱॱ = false;
        if (this.ˎ != null) {
            this.ˎ.ॱ(8);
            this.ˎ = null;
        }
    }
}
